/*
#################################################################################
#
# Copyright (c) 2006 Michigan State University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#################################################################################

#################################################################################
#
#	Author:
#		Nathan Collins <npcollins@gmail.com>
#
#################################################################################
*/

/* flag whether history div is visible */

var hist_visible = 0;

/* end */


/* show the history div */

function showHistory() {
	h = document.getElementById('history');
	hw = document.getElementById('historyFloat');
	/* scroll bar width fix */
	scbr = (window.innerWidth - document.width) / 2;
	hw.style.right = document.width + scbr - (h.offsetLeft + h.offsetWidth);
	/* hw.style.top = h.offsetTop + h.offsetHeight + 1; */
	if (hist_visible == 0) {
		hw.style.visibility = 'visible';
		hw.style.opacity = 0.95;
		hist_visible = 1;
	}
}

/* end */


/* hide the history div */

function closeHistory() {
	document.getElementById('historyFloat').style.right = 20;
	document.getElementById('historyFloat').style.visibility = 'hidden';
	hist_visible = 0;
}

/* end */


/* toggle the show/hide history link */

function replaceHistory(show) {
	hw = document.getElementById('history');
	if (show) {
		hw.innerHTML = "<span class=\"smallish details\"><a onClick=\"replaceHistory(); closeHistory();\">History&nbsp;&#9660;&nbsp;</a></span><br>";
	}
	else {
		hw.innerHTML = "<span class=\"smallish details\"><a onClick=\"replaceHistory(1); showHistory()\">History&nbsp;&#9668;&nbsp;</a></span><br>";
	}
}

/* end */


/* save the search in the history cookie */

function addSearchHistory(searchstr) {
	addCookieList("history", searchstr);
}

/* end */


/* pull history of searches as an array */

function getSearchHistory() {
	/* pull the array of searches from history */
	hist = getCookieList("history");

	/* reverse it so most recent search is first */
	hist.reverse();

	/* history div contents */
	hcont = ""

	/* loop through searches */
	for (srch in hist) {
		url = "search.py?s=" + encodeURIComponent(hist[srch]);

		hcont += "<div class='historyResult'>&nbsp;<a href='" + url + "' class='noUL'>" + hist[srch].substring(0, 80) + "</a>&nbsp;</div>";
	}

	/* place search history into its div */
	document.getElementById("historyFloat").innerHTML = hcont;
}

/* end */

